package com.rainner.admin.server;

import java.sql.SQLException;
import java.util.List;

import com.rainner.admin.javabean.ManagerRoleBean;
import com.rainner.admin.util.dbutil.BaseService;

public class ManagerRoleServer extends BaseService<ManagerRoleBean>{
	
	/**
	 * 返回操作员拥有的所有角色
	 * @param managerName
	 * @return
	 * @throws SQLException
	 */
	public List<ManagerRoleBean> allManagerRoleData(String managerName) throws SQLException{
		String sqlSelect = "select * from ManagerRole where ManagerName = ?";
		return super.query(sqlSelect, managerName);
	}
	/**
	 * 插入操作员角色
	 * @param managerName
	 * @param roleId
	 * @return
	 * @throws SQLException
	 */
	public boolean addOperatorRole(String managerName,String roleId) throws SQLException{
		String sqlselect = "select * from ManagerRole where managerName = ? and roleId = ?";
		if(super.query(sqlselect, managerName,roleId).size() < 1){
			String sqlinsert = "insert into ManagerRole(ManagerName,RoleId) values(?,?)";
			return super.update(sqlinsert, managerName,roleId);
		}
		return true;
	}
	/**
	 * 删除操作员角色
	 * @param managerName
	 * @param roleId
	 * @return
	 * @throws SQLException
	 */
	public boolean delOperatorRole(String managerName,String roleId) throws SQLException{
		String sqlselect = "select * from ManagerRole where managerName = ? and roleId = ?";
		if(super.query(sqlselect, managerName,roleId).size() > 0){
			String sqlinsert = "delete from ManagerRole where ManagerName = ? and RoleId = ?";
			return super.update(sqlinsert, managerName,roleId);
		}
		return true;
	}
}
